/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package etf.pia.controlers;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import lombok.Getter;
import lombok.Setter;
import etf.pia.entity.*;
import etf.pia.util.ServerUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Set;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Alejandro
 */
@Getter
@Setter
@ManagedBean(name = "projectBean")
@SessionScoped
public class ProjectBean implements Serializable {

    private ArrayList<Projekti> projectList = null;

    public ProjectBean() {
        load();
    }

    private void load() {
        Session ses = ServerUtil.getSessionFactory().getCurrentSession();
        Transaction t = ses.beginTransaction();
        try {
            Criteria c = ses.createCriteria(Projekti.class);
            projectList = new ArrayList<Projekti>(c.list());
            t.commit();
        } catch (Exception e) {
            t.rollback();
            e.printStackTrace();
        }
    }

    public boolean noProjects() {
        return (0 == projectList.size());
    }

}
